package des.yordan.mihaylov;

import java.util.Comparator;

/**
 * @author Yordan Mihaylov
 * @version 2011/05/15
 */

public class EventChain {

	private SortableQueue<SortableQueueItem> eventQueue;

	public EventChain() {
		eventQueue = new SortableQueue<SortableQueueItem>(
				new Comparator<SortableQueueItem>() {
					@Override
					public int compare(SortableQueueItem o1,
							SortableQueueItem o2) {
						if (o1.simulationTime < o2.simulationTime)
							return -1;
						else if (o1.simulationTime > o2.simulationTime)
							return 1;
						else
							return 0;
					}
				});
	}

	public void addEvent(SimEvent e) {
		eventQueue.addElement(e);
	}

	// may return NULL if the queue is empty
	public SimEvent getNextEvent() {
		return (SimEvent) eventQueue.getNextElement();
	}
}
